package com.szy.bigevent.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.szy.bigevent.mapper.ArticleMapper;
import com.szy.bigevent.pojo.Article;
import com.szy.bigevent.service.ArticleService;
import com.szy.bigevent.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public PageInfo<Article> selectAll(Integer pageSize, Integer pageNum, Article article) {
        PageHelper.startPage(pageNum, pageSize);
        List<Article> list = articleMapper.selectAll(article);
        PageInfo<Article> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public int deleteById(Integer id) {
        return articleMapper.deleteById(id);
    }

    @Override
    public int insertSelective(Article record) {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");
        record.setCreateUser(id);
        return articleMapper.insertSelective(record);
    }

    @Override
    public int updateByIdSelective(Article record) {
        return articleMapper.updateByIdSelective(record);
    }
}
